package cn.xc.system.controller;


import cn.xc.basic.util.AjaxResult;
import cn.xc.basic.util.PageList;
import cn.xc.system.domain.Systemdictionarydetail;
import cn.xc.system.query.SystemdictionarydetailQuery;
import cn.xc.system.service.ISystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {

    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailSeriver;

    @GetMapping("/{id}")
    public Systemdictionarydetail loadById(@PathVariable("id") Long id){
        return systemdictionarydetailSeriver.loadById(id);
    }

    @GetMapping
    public List<Systemdictionarydetail> loadAll(){
        return systemdictionarydetailSeriver.loadAll();
    }

    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            systemdictionarydetailSeriver.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            if (systemdictionarydetail.getId()==null){
                systemdictionarydetailSeriver.save(systemdictionarydetail);
            }else {
                systemdictionarydetailSeriver.update(systemdictionarydetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PostMapping
    public PageList<Systemdictionarydetail> queryPage(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
            return systemdictionarydetailSeriver.queryPage(systemdictionarydetailQuery);
    }

    @PatchMapping
    public AjaxResult patchRemove(@RequestBody List<Long> ids){
        try {
            systemdictionarydetailSeriver.patchRemove(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }



    @GetMapping("/drawer/{id}")
    public List<Systemdictionarydetail> drawerById(@PathVariable("id") Long id){
        return systemdictionarydetailSeriver.drawerById(id);
    }


}
